﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using serviceMaker.RssService;
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight.Command;

namespace ViewModel.Rss
{
    public class RemoveRssViewModel : AddRssViewModel
    {
        public ICommand RemoveFeeds
        { get; set; }

   

        public void ExecuteRemoveFeeds()
        {
            if (SelectedFeeds != null)
            {
                List<Guid> listRemove = new List<Guid>();
                RssService.eraseListRssFromDirectoryCompleted += (obj, arg) =>
                {
                  if (arg != null && arg.Error == null && arg.Result != null)
                   {
                       Messenger.Default.Send<string>("FluxRss", "reload");
                   } 

                };
              
                foreach (object obj in SelectedFeeds)
                    if (obj is DataRss)
                        listRemove.Add(((DataRss)obj).id);

                if (clientInfos.userRootDirectory != null)
                RssService.eraseListRssFromDirectoryAsync(new eraseListRssFromDirectoryRequest(clientInfos.userRootDirectory, clientInfos.CurrentUser.id, listRemove));
                Messenger.Default.Send<string>("AnswerSaveRss", "AnswerRemoveRss");
           }
        }

        public bool CanExecuteRemoveFeeds()
        {
            return true;
        }

    }
}
